import { Consumer } from '../Function'
import { Event } from './Event'
import { EventRegistry } from './EventRegistry'

/**
 *  EventCenter
 * @author LL
 * @date 2022/1/27 17:31
 */
export interface EventCenter<E extends EventRegistry> {
    /**
     * 事件发布
     * @param {Event} event
     */
    push(event: Event): void

    /**
     * 事件监听
     * @param {K} name
     * @param {Consumer<E[K]>} callback
     */
    addEventListener<K extends keyof E>(name: K, callback: Consumer<E[K]>): number

    /**
     * 事件监听
     * @param {K} name
     * @param {Consumer<E[K]>} callback
     */
    addOnceEventListener<K extends keyof E>(name: K, callback: Consumer<E[K]>): number

    /**
     * 取消事件监听
     * @param {K} name
     * @param id
     */
    removeEventListener<K extends keyof E>(name: K, id: any): void
}
